//
//  THJAcountDetailVC.m
//  THJXHW
//
//  Created by 河南德艺 on 2018/8/9.
//  Copyright © 2018年 河南德艺. All rights reserved.
//

#import "THJAcountDetailVC.h"
#import "THJAcountDetailNormalcell.h"
#import "THJAcountDetailHeadCell.h"

@interface THJAcountDetailVC ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView * _tableview;
    NSDictionary * infoDic;
}
@end


@implementation THJAcountDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self SVHUDShow];
    [self getData];
    if(KIsiPhoneX){
        [self setXNavBarWithTitle:@"账户详情"];
    }else{
        [self setNavBarWithTitle:@"账户详情"];
    }
     _tableview =  [self setTableviewWithFrame:CGRectMake(0, NavbarHeight, ScreenWidth, ScreenHeight-NavbarHeight) RegisterNibNameArr:@[@"THJAcountDetailNormalcell",@"THJAcountDetailHeadCell"] ReuseIdentifierArr:@[@"cell0",@"cell1"] RowHeight:0 BgColor:SingleColor(whiteColor) IsLoadMore:NO];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        return 130;
    }else{
        return 120;
    }
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 7;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSArray * titleArr = @[@"中信账户名",@"中信账号",@"出金账户名",@"出金账户",@"出金开户行",@"出金联行号"];
    NSArray * indexArr = @[@"subaccnm",@"subaccno",@"bankName",@"bankID",@"bank",@"bankLID"];
    if(indexPath.row == 0){
        THJAcountDetailHeadCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath];
        if(infoDic){
            cell.lab1.text = [RSA decryptString:infoDic[@"money"] publicKey:RSA_PubKey];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        THJAcountDetailNormalcell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell0" forIndexPath:indexPath];
        cell.titleLab.text = titleArr[indexPath.row - 1];
        if(infoDic){
            NSString * content = infoDic[indexArr[indexPath.row - 1]];
            cell.contentLab.text = [RSA decryptString:content publicKey:RSA_PubKey];
            NSLog(@"cell-info:%@",cell.contentLab.text);
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
-(void)getData{
    NSString * mobile = [RSA encryptString:[THJTools getMobile] publicKey:RSA_PubKey];
    NSLog(@"phonekk-%@",[THJTools getMobile]);
    [THJNetWork postNetDataFromUrl:@"http://p.thjb.net/thjblink/appdata.php?action=hjb_info" parameters:@{@"mobile":mobile,@"type":@"ios"} callback:^(NSDictionary *  receiveData, NSError *error) {
        NSLog(@"账号信息--%@",receiveData);
        [self SVHUDHiden];
        if([receiveData[@"status"] isEqual:@"success"]){
            infoDic = receiveData[@"data"];
            [_tableview reloadData];
        }else{
            [self HUDShowMsg:@"获取信息失败" AfterDelayDimiss:1];
        }
        
    }];
}
@end
